// function deployFundMe() {
//     console.log("this is a deploy function")
// }

const { network } = require("hardhat");
const { devlopmentChains, networkConfig, LOCK_TIME, CONFIRMATIONS } = require("../helper-hardhat-config");

// if (devlopmentChains.includes(network.name)) {
//     console.log("This is a devlopment chain")

// module.exports = deployFundMe
// module.exports = async function (hre) {
//     const getNamdeAccount = hre.getNamdeAccounts
//     const deployments = hre.deployments

//     console.log("this is a deploy function")
// }

module.exports = async ({ getNamedAccounts, deployments }) => {
    // const firstAccount = (await getNamedAccounts()).firstAccount
    // console.log(`first account is ${firstAccount}`)
    // const { deploy } = deployments
    // await deploy("FundMe", {
    //     from: firstAccount,
    //     args: [180],
    //     log: true
    // })
    const { firstAccount } = await getNamedAccounts()
    const { deploy } = deployments

    let dataFeedAddress
    let confirmations
    if (devlopmentChains.includes(network.name)) {
        const mockV3Aggregator = await deployments.get("MockV3Aggregator")
        dataFeedAddress = mockV3Aggregator.address
        confirmations = 0
    } else {
        dataFeedAddress = networkConfig[network.config.chainId].ethUsdDataFeed
        confirmations = CONFIRMATIONS
    }

    const fundMe = await deploy("FundMe", {
        from: firstAccount,
        args: [LOCK_TIME, dataFeedAddress],
        log: true,
        waitConfirmations: confirmations
    })

    if (Headers.network.config.chainId === 11155111 && process.env.ETHERSCAN_API_KEY) {
        await hre.run("verify:verify", {
            address: fundMe.address,
            constructorArguments: [LOCK_TIME, dataFeedAddress]
        })
    } else {
        console.log("This is not mainnet")
    }

}

module.exports.tags = ["all", "fundme"]